<div ng-controller='query' ng-init="init()" class="query-panel">
  <div ng-repeat="id in (unPinnedQueries = (querySrv.ids|pinnedQuery:false))" ng-class="{'short-query': unPinnedQueries.length>1}">
    <form class="form-search" style="position:relative;margin-bottom:5px;" ng-submit="refresh()">
      <span class="begin-query">
        <i class="icon-circle pointer" data-unique="1" bs-popover="'app/panels/query/meta.html'" data-placement="right" ng-style="{color: querySrv.list[id].color}"></i>
        <i class="icon-remove-sign pointer remove-query" ng-show="querySrv.ids.length > 1" ng-click="querySrv.remove(id);refresh()"></i>
      </span>
      <input class="search-query panel-query" ng-class="{ 'input-block-level': unPinnedQueries.length==1, 'last-query': $last, 'has-remove': querySrv.ids.length > 1 }" bs-typeahead="panel.history" data-min-length=0 data-items=100 type="text" ng-model="querySrv.list[id].query" />
      <span class="end-query">
        <i class="icon-search pointer" ng-click="refresh()" ng-show="$last"></i>
        <!-- Remove the plus icon to disable multiple queries function -->
        <i class="icon-plus pointer" ng-click="querySrv.set({})" ng-show="$last"></i>
        <i class="icon-eraser pointer" ng-click="reset()" ng-show="$last"></i>
      </span>
    </form>
  </div>
  <div style="display:inline-block" ng-repeat="id in querySrv.ids|pinnedQuery:true">
    <span class="pointer" ng-show="$first" ng-click="panel.pinned = !panel.pinned"><small class="pins">Pinned</small> <i ng-class="{'icon-caret-right':panel.pinned,'icon-caret-left':!panel.pinned}"></i></span>
    <span ng-show="panel.pinned" class="pinned badge">
      <i class="icon-circle pointer" ng-style="{color: querySrv.list[id].color}" data-unique="1" bs-popover="'app/panels/query/meta.html'"></i><span bs-tooltip="querySrv.list[id].query"> {{querySrv.list[id].alias || querySrv.list[id].query}}</span>
    </span>
  </div>
  <span style="display:inline-block" ng-show="unPinnedQueries.length == 0">
    <i class="icon-search pointer" ng-click="refresh()"></i>
    <i class="icon-plus pointer" ng-click="querySrv.set({})"></i>
  </span>
</div>
